<?php
namespace App\Models;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/4
 * Time: 12:53
 */
class Log extends BaseModel
{
    protected $table = "log";

    public function getOne($where, $fileds = '*', $order = '')
    {
        if (!$order) {
            $order = ['id' => 'desc'];
        }
        return $this->multiSelect($fileds)->multiWhere($where)->multiOrder($order)->first();
    }

    /**
     * 按条件查询全部数据,根据配置显示条数显示
     */
    public function getList(array $where = [], $fields = '*', $order = '', $pageSize = '')
    {
        if ($pageSize) {
            return $this->multiSelect($fields)->multiWhere($where)->multiOrder($order)->paginate($pageSize);
        } else {
            return $this->multiSelect($fields)->multiWhere($where)->multiOrder($order)->get();
        }
    }

    /**
     *插入数据
     */
    public function add($data)
    {
        return $this->_add($data);
    }


    /***
     * @param array $id
     * @param array $data
     * 更新数据
     */
    public function up($where, $data)
    {
        return $this->_updata($where, $data);
    }

    /**
     * @param $id
     * 删除数据
     */
    public function del($where)
    {
        return $this->_del($where);
    }

    /**
     * 记录日志
     * @param $order 订单
     * @param $type 1 充值  2 提现
     * @return array
     */
    public function addLog($order,$type){
        if(empty($order)){
            $res = ['state'=>400,'msg'=>'订单信息错误'];
            return $res;
        }
        $data['member_id'] = $order['member_id'];
        $data['type'] = 1;
        $data['amount'] = "+".$order['actual_arrival'];
        if($type==2){
            $data['type'] = 2;
            $data['amount'] = "-".$order['tx_amount'];
        }
        $data['created_at'] = date("Y-m-d H:i:s",time());
        $data['updated_at'] = date("Y-m-d H:i:s",time());
        $res = $this->add($data);
        return $res;
    }
}